home *** CD-ROM | disk | FTP | other *** search
- unit DlogStuff;
- interface
- uses
- Quickdraw, Picker, Palettes, SANE, WindowStuff;
-
- const
- OK_ALRT_ID = 1005;
- YN_ALRT_ID = 1006;
- YNC_ALRT_ID = 1007;
-
- procedure DoMessage (mes0: str255; mes1: str255; mes2: str255; mes3: str255);
- procedure DoOneLiner (mes0: str255);
- procedure Do_OK_ALRT;
- function Do_YN_ALRT: Boolean;
- function Do_YNC_Alrt: integer;
- function CheckForStop (theEvent: EventRecord): boolean;
- procedure DrawDefaultBtn (theItem: integer; thisDlog: DialogPtr);
- procedure HiLiteDLOGButton (theItem: integer; state: boolean; thisDlog: DialogPtr);
- procedure ClickButton (Dptr: DialogPtr; ItemNo: integer);
- procedure DLOGTitle (title, FcnName: str255);
- function GetDBox (theDLOG: dialogPtr; theItem: integer): rect;
- function GetDLOGIHandle (theDLOG: dialogPtr; theItem: integer): Handle;
- procedure WriteLabel (theStr: Str255; theRect: rect; toTheRight: boolean);
- procedure ZoomRect (zoomUp: boolean; smallRect, bigRect: rect);
- procedure ShadowBox (theRect: Rect);
-
- procedure Add_List_String (theString: Str255; theList: ListHandle);
-
- procedure PushRadioButton (theDlog: dialogPtr; item, first, last: integer);
- procedure CheckABox (theDlog: dialogPtr; ItemNum: integer; HighLite: boolean);
- procedure TrackScroll (theControl: ControlHandle; partCode: Integer);
-
-
- function IsStringReal (theStr: str255; var ItsBadBecause: str255): boolean;
- function String2Int (theStr: str255): integer;
- function Int2String (theInt: integer): str255;
- function String2Real (aStr: str255): real;
- function Real2String (aReal: real): str255;
-
- implementation
-
-
-
- {======================================================================================= }
- procedure DoMessage; {(mes0 : str255;mes1 : str255; mes2 : str255;mes3 : str255);}
- const
- MessageDialog = 258;
- var
- dialogP: DialogPtr;
- item: integer;
- oldPort: grafPtr;
- begin
- GetPort(oldPort);
- ParamText(mes0, mes1, mes2, mes3);
- dialogP := GetNewDialog(MessageDialog, nil, pointer(-1));
- if dialogP = nil then
- begin
- SysBeep(5);
- end
- else
- begin
- CenterWindow(dialogP);
- ShowWindow(dialogP);
- InitCursor;
- ModalDialog(nil, item);
- DisposDialog(dialogP);
- end;
- SetPort(oldPort);
- end; {DoMessage}
-
-
- {======================================================================================= }
- procedure DoOneLiner; {(mes0: Str255)}
- begin
- DoMessage(mes0, '', '', '');
- end; {DoOneLiner}
-
-
- {======================================================================================= }
- {Make sure your message has already been prepared using ParamText}
- procedure Do_OK_ALRT;
- var
- oldPort: GrafPtr;
- dummy: integer;
- begin
- GetPort(oldPort);
- dummy := StopAlert(OK_ALRT_ID, nil);
- SetPort(oldPort);
- end; {Do_OK_ALRT}
-
-
- {======================================================================================= }
- {Make sure your message has already been prepared using ParamText}
- function Do_YN_ALRT: Boolean;
- var
- oldPort: GrafPtr;
- begin
- GetPort(oldPort);
- if (Alert(YN_ALRT_ID, nil) = 1) then
- Do_YN_ALRT := TRUE
- else
- Do_YN_ALRT := FALSE;
- SetPort(oldPort);
- end; {Do_YN_ALRT}
-
-
-
- {======================================================================================= }
- {Make sure your message has already been prepared using ParamText}
- function Do_YNC_Alrt: integer;
- var
- oldPort: GrafPtr;
- begin
- GetPort(oldPort);
- Do_YNC_Alrt := Alert(YNC_ALRT_ID, nil);
- SetPort(oldPort);
- end; {Do_YNC_Alrt}
-
-
- {======================================================================================= }
- {This is a routine used to add strings to an existing list}
- procedure Add_List_String; {(theString: Str255; theList: ListHandle)}
- var
- theRow: integer; {The Row that we are adding}
- aStr: str255;
- aPt: point;
- begin
- if (theList <> nil) then
- begin
- aPt.h := 0; {Point to the correct column}
- theRow := LAddRow(1, 200, theList); {Add another row at the end of the list}
- aPt.v := theRow; {Point to the row just added}
- aStr := theString;{Get the string to add}
- LSetCell(Pointer(ord(@aStr) + 1), length(aStr), aPt, theList);{Place string in row just created}
- LDraw(aPt, theList); {Draw the new string}
- end;
- end;
-
-
- {======================================================================================= }
- {--------------------Scan Event Queue for Cmd-Period---------------------}
-
- {example of code that might call CheckForStop }
- { itsAnEvent := EventAvail(keyDownMask, myEvent);}
- { if itsAnEvent then}
- { begin}
- { if CheckForStop(myEvent) then}
- { goto 99;}
- { end;}
-
- function CheckForStop;{ (theEvent : EventRecord) : boolean}
- type
- Trick = packed record
- case boolean of
- true: (
- long: Longint
- );
- false: (
- chr3, chr2, chr1, chr0: char
- )
- end;
- var
- CharCode: char;
- TrickVar: Trick;
- stop: boolean;
- periodKey: char;
- begin
- stop := FALSE;
- periodKey := chr(46);
- TrickVar.long := theEvent.message;
- CharCode := TrickVar.chr0;
- if BitAnd(theEvent.modifiers, CmdKey) = CmdKey then
- if CharCode = periodKey then
- stop := TRUE;
- CheckForStop := stop;
- end;
-
- {--------------------Check/Uncheck CheckBoxes in DLOGs---------------------}
- procedure CheckABox;{(theDlog:dialogPtr; ItemNum : integer;HighLite : boolean);}
- var
- itemtype: integer; {the dialog items type}
- itemhandle: handle; {the dialog items handle}
- itemrect: rect; {the dialog items rect}
- itemcntlhand: controlhandle; {we convert the items handle to a cntl handle}
-
- begin
- GetDItem(theDlog, ItemNum, itemtype, itemhandle, itemrect); {get the handle}
- itemcntlhand := controlhandle(itemhandle); {convert it to a cntl handle}
- if HighLite then
- begin
- SetCtlValue(itemcntlhand, 1); {hilite the control}
- end
- else
- begin
- SetCtlValue(itemcntlhand, 0); {unlilite the control}
- end;
- end;
-
- {-----------------Track User's Use of Scrollbar---------------}
-
- procedure TrackScroll; {(theControl: ControlHandle; partCode: Integer)}
- var
- min, max, amount, startValue: Integer;
- up: Boolean;
- begin
- up := partcode in [inUpButton, inPageUp];
- min := GetCtlMin(theControl);
- max := GetCtlMax(theControl);
- startValue := GetCtlValue(theControl);
- if ((up and (startValue > min)) or ((not up) and (startValue < max))) and (partCode <> 0) then
- begin
- if up then
- amount := -1
- else
- amount := 1;
- if partCode in [inPageUp, inPagedown] then
- amount := round(amount * 5)
- else
- amount := round(amount * 1);
- SetCtlValue(theControl, amount + startValue);
- end;
- end; {of TrackScroll}
-
- {--------------------HiLite/UnHilite Radio Buttons---------------------}
- procedure PushRadioButton; {(theDlog : dialogPtr; item, first, last : integer)}
-
- var
- index: integer; {index through the loop}
- itemtype: integer; {the dialog items type}
- itemhandle: handle; {the dialog items handle}
- itemrect: rect; {the dialog items rect}
- itemcntlhand: controlhandle; {we convert the items handle to a cntl handle}
-
- begin
- for index := first to last do {do it for all items in the group}
- begin
- GetDItem(theDlog, index, itemtype, itemhandle, itemrect); {get the handle}
- itemcntlhand := controlhandle(itemhandle); {convert it to a cntl handle}
- if (index = item) then
- begin
- SetCtlValue(itemcntlhand, 1); {hilite the control}
- end
- else
- SetCtlValue(itemcntlhand, 0); {unlilite the control}
- end;
- end;
-
- {--------------------Outline DLOGs Default Button---------------------}
- procedure DrawDefaultBtn; {(theItem : integer; thisDlog : DialogPtr);}
- var
- OptType: Integer;
- OptBox: Rect;
- ItemHdl: Handle;
- oldDlog: DialogPtr;
-
- begin
- GetPort(oldDlog);
- SetPort(thisDlog);{ set window to current graf port }
- {Note: GetDItem gets info about dialogs}
- GetDItem(thisDlog, theItem, OptType, ItemHdl, OptBox); { get item location }
- Pensize(3, 3); { no wimpy outlines here }
- InsetRect(OptBox, -4, -4); { set rectangle around button }
- FrameRoundRect(OptBox, 16, 16); { draw the sucker! }
- PenSize(1, 1); { reset the PenSize}
- SetPort(oldDlog); { RESET to the original port}
- end; { of proc DrawDefaultBtn }
-
-
- procedure HiLiteDLOGButton; {(theItem: integer; state: boolean; thisDlog: DialogPtr)}
- const
- on = TRUE;
- off = FALSE;
- var
- tipe: integer;
- aHdl: Handle;
- tempRect: rect;
- begin
- GetDItem(thisDlog, theItem, tipe, aHdl, tempRect); {Get the item handle}
-
- if state = on then
- HiliteControl(controlhandle(aHdl), 0) {un-dim button}
- else
- HiliteControl(controlhandle(aHdl), 255); {Dim the button}
- end;{}
-
- {--------------------Draw DLOG Title-------
- rect4.right := ZoomBlend(smallRect.right, bigRect.right);
- rect4.top := ZoomBlend(smallRect.top, bigRect.top);
- rect4.bottom := ZoomBlend(smallRect.bottom, bigRect.bottom);
-
- FrameRect(rect4);
- FrameRect(rect1);
- rect1 := rect2;
- rect2 := rect3;
- rect3 := rect4;
-
- fract := FixMul(fract, factor);
- end;
- FrameRect(rect1);
- FrameRect(rect2);
- FrameRect(rect3);
- PenNormal;
- end;
-
- {===========================================================}
- {draws a 2-pixel shadow around a rectangle}
- procedure ShadowBox; {(theRect: Rect)}
- begin
- PenSize(2, 2);
- with theRect do
- begin
- MoveTo(left + 2, bottom);
- LineTo(Right, bottom);
- MoveTo(right, Top + 2);
- LineTo(Right, Bottom);
- end;
- PenSize(1, 1);
- FrameRect(theRect);
- end;{ShadowBox}
-
-
-
-
- {--------------------Simulate MouseDown in Button---------------------}
- procedure ClickButton; {(Dptr : DialogPtr; ItemNo : integer);}
-
- { Inside Macintosh leaves out the fact that if you use a filter procedure }
- {in the ModalDialog call you need to simulate a clicking of the OK button when }
- {the return key is hit. This one of two possible techniques where we directly }
- {highlight and unhighlight the button. The other technique would be to add a }
- {mouse down event to the event queue in which the mouse coordinates are }
- {somewhere inside of the OK button. JWIND}
-
- var
- IType: integer;
- ButtonHandle: Handle;
- Box: rect;
- L: LongInt;
-
- begin
- GetDItem(Dptr, ItemNo, IType, ButtonHandle, Box);
- HiliteControl(ControlHandle(ButtonHandle), 253);
- Delay(8, L);
- HiliteControl(ControlHandle(ButtonHandle), 0);
- end; { ClickButton }
-
-
- {check to see if the string passed contains only numerals and a decimal}
- {Returns a string explaining what was wring, if anything}
- function IsStringReal; {(theStr : str255; var ItsBadBecause : str255) : boolean;}
- label
- 99;
- var
- i, decimalFound, negativesFound: integer;
- aChar: char;
- Okay: boolean;
- begin
- okay := TRUE;
- decimalFound := 0;
- negativesFound := 0;
- ItsBadBecause := '';
- for i := 1 to length(theStr) do
- begin
- aChar := Copy(theStr, i, 1);
- if aChar = '.' then
- decimalFound := decimalFound + 1;
- if decimalFound > 1 then
- begin
- ItsBadBecause := 'Too many decimals found';
- okay := FALSE;
- goto 99;
- end;{if decimalFound > 1 then}
- if aChar = '-' then
- negativesFound := negativesFound + 1;
- if negativesFound > 1 then
- begin
- ItsBadBecause := 'Too many "-"s found ';
- okay := FALSE;
- goto 99;
- end;{if negativesFound > 1 then}
- if not (aChar in ['0'..'9', '-', '.']) then
- begin
- ItsBadBecause := Concat('Non-numeric character found: ', aChar);
- okay := FALSE;
- goto 99;
- end;{if not aChar in ['0'..'9', '-','.'] then}
- end;{for i := 1 to length(theStr)}
- 99:
- IsStringReal := Okay;
- end;{IsStringReal}
-
-
-
-
-
- {----------------Convert a Numeric String to an Integer----------------}
- function String2Int;{(theStr) : integer;}
- var
- aLongInt: longint;
- begin
- StringToNum(theStr, aLongInt);
- if aLongInt > maxInt then
- begin
- DoMessage('That number is too big.', 'It must be less than 32767', '', '');
- aLongInt := 0;
- end;
- String2Int := aLongInt;
- end;{String2Int}
-
- {----------------Convert a Numeric String to an Integer----------------}
- function Int2String; {(theInt) : str255;}
- var
- aLongInt: longint;
- aStr: str255;
- begin
- aLongInt := theInt;
- NumToString(aLongInt, aStr);
- Int2String := aStr;
- end;{String2Int}
-
- {--------------------Convert a Real to a Str255---------------------}
- function Real2String; {(aReal : real) : str255;}
- var
- aDecForm: DecForm;
- aDecStr: DecStr;
- aStr: str255;
- begin
- aDecform.Style := FixedDecimal;
- aDecform.digits := 2;
- Num2Str(aDecForm, aReal, aDecStr);
- aStr := aDecStr;
- Real2String := aStr;
- end;{Real2Str}
-
- {--------------------Convert a Str255 to a Real---------------------}
- {This is actually very simpleā¦}
- function String2Real; {(aStr : str255) : real;}
- begin
- String2Real := Str2Num(aStr);
- end;{String2Real}
-
-
-
- end.